package com.yuju.controller.order;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.yuju.common.PageModel;
import com.yuju.common.Result;
import com.yuju.common.fileld.validator.FieldValidator;
import com.yuju.controller.base.BaseController;
import com.yuju.enums.ReturnCodeEnum;
import com.yuju.enums.ReturnStatusEnum;
import com.yuju.group.enums.GuestInfoReturnCodeEnum;
import com.yuju.group.model.GuestInfoModel;
import com.yuju.order.enums.RoomOrderGuestReturnCodeEnum;
import com.yuju.order.enums.RoomOrderReturnCodeEnum;
import com.yuju.order.model.RoomOrderGuestModel;
import com.yuju.order.model.RoomOrderModel;
import com.yuju.order.service.IRoomOrderGuestService;
import com.yuju.util.Utils;
import com.yuju.vo.order.RoomOrderGuestVO;
import com.yuju.vo.order.RoomOrderVO;
/**
 * 
 * 类名：RoomOrderGuestController  <br />
 *
 * 功能：
 *
 * @author : sunyl <br />
 * @Date : 2017年11月25日 下午5:53:17  <br />
 * @version : 1.1 <br />
 */
@Controller
@RequestMapping("roomOrderGuest")
public class RoomOrderGuestController extends BaseController<RoomOrderGuestVO, RoomOrderGuestModel> {
	@Autowired
	private IRoomOrderGuestService roomOrderGuestService;
	
	@RequestMapping("list")
	@ResponseBody
	public Result list(@RequestBody JSONObject jsonObject)   {
		RoomOrderGuestVO RoomOrderGuestVO = jsonObject.toJavaObject(RoomOrderGuestVO.class);
		// 参数校验
		Map<String, String> fail = FieldValidator.validateAll(RoomOrderGuestVO, "pager", true);
		if (!fail.isEmpty()) {
			return validateError(fail);
		}
		Result result = new Result();
		PageModel pageModel = roomOrderGuestService.pageList(convert(RoomOrderGuestVO), RoomOrderGuestVO.getPage(), RoomOrderGuestVO.getPageSize());
		if (Utils.isNotNull(pageModel) && Utils.isNotNull(pageModel.getRows())) {
			result.setTotal(pageModel.getTotal());
			result.setRows(pageModel.getRows());
			result.setStatus(ReturnStatusEnum.SUCCESS.getCode());
			result.setMsg(ReturnStatusEnum.SUCCESS.getDesc());
			result.setReturnCode(RoomOrderGuestReturnCodeEnum.ROOM_ORDER_GUEST_QUERY_SUCCESS.getCode());
			result.setReturnMsg(RoomOrderGuestReturnCodeEnum.ROOM_ORDER_GUEST_QUERY_SUCCESS.getDesc());
		} else {
			result = new Result();
			result.setStatus(ReturnStatusEnum.FAILURE.getCode());
			result.setMsg(ReturnStatusEnum.FAILURE.getDesc());
			result.setReturnCode(ReturnCodeEnum.NO_DATA.getCode());
			result.setReturnMsg(ReturnCodeEnum.NO_DATA.getDesc());
		}
		return result;
	}
	/**
	 * 单纯列表 不分页
	 * 功能：<br/>
	 *
	 * @author sunyl
	 * @Date 2017年12月19日 上午11:34:36 <br/>
	 */
	@RequestMapping("listPure")
	@ResponseBody
	public Result listPure(@RequestBody JSONObject jsonObject)   {
		
		RoomOrderGuestVO RoomOrderGuestVO = jsonObject.toJavaObject(RoomOrderGuestVO.class);
		// 参数校验
		Map<String, String> fail = FieldValidator.validateAll(RoomOrderGuestVO, "roomOrderId", true);
		if (!fail.isEmpty()) {
			return validateError(fail);
		}
		Result result = new Result();
		List<RoomOrderGuestModel> roomorderGuestList = roomOrderGuestService.list(convert(RoomOrderGuestVO));
		if (Utils.isNotNull(roomorderGuestList) && roomorderGuestList.size()>0) {
			result.setData(roomorderGuestList);
			result.setStatus(ReturnStatusEnum.SUCCESS.getCode());
			result.setMsg(ReturnStatusEnum.SUCCESS.getDesc());
			result.setReturnCode(RoomOrderGuestReturnCodeEnum.ROOM_ORDER_GUEST_QUERY_SUCCESS.getCode());
			result.setReturnMsg(RoomOrderGuestReturnCodeEnum.ROOM_ORDER_GUEST_QUERY_SUCCESS.getDesc());
		} else {
			result = new Result();
			result.setStatus(ReturnStatusEnum.FAILURE.getCode());
			result.setMsg(ReturnStatusEnum.FAILURE.getDesc());
			result.setReturnCode(ReturnCodeEnum.NO_DATA.getCode());
			result.setReturnMsg(ReturnCodeEnum.NO_DATA.getDesc());
		}
		return result;
	}
	/**
	 * 单纯列表 不分页
	 * 功能：<br/>
	 *
	 * @author sunyl
	 * @Date 2017年12月19日 上午11:34:36 <br/>
	 */
	@RequestMapping("listPureForGuest")
	@ResponseBody
	public Result listPureForGuest(@RequestBody JSONObject jsonObject)   {
		
		RoomOrderGuestVO RoomOrderGuestVO = jsonObject.toJavaObject(RoomOrderGuestVO.class);
		// 参数校验
		Map<String, String> fail = FieldValidator.validateAll(RoomOrderGuestVO, "roomOrderId", true);
		if (!fail.isEmpty()) {
			return validateError(fail);
		}
		Result result = new Result();
		List<RoomOrderGuestModel> roomorderGuestList = roomOrderGuestService.listPure(convert(RoomOrderGuestVO));
		if (Utils.isNotNull(roomorderGuestList) && roomorderGuestList.size()>0) {
			result.setData(roomorderGuestList);
			result.setStatus(ReturnStatusEnum.SUCCESS.getCode());
			result.setMsg(ReturnStatusEnum.SUCCESS.getDesc());
			result.setReturnCode(RoomOrderGuestReturnCodeEnum.ROOM_ORDER_GUEST_QUERY_SUCCESS.getCode());
			result.setReturnMsg(RoomOrderGuestReturnCodeEnum.ROOM_ORDER_GUEST_QUERY_SUCCESS.getDesc());
		} else {
			result = new Result();
			result.setStatus(ReturnStatusEnum.FAILURE.getCode());
			result.setMsg(ReturnStatusEnum.FAILURE.getDesc());
			result.setReturnCode(ReturnCodeEnum.NO_DATA.getCode());
			result.setReturnMsg(ReturnCodeEnum.NO_DATA.getDesc());
		}
		return result;
	}
	
	@RequestMapping("save")
	@ResponseBody
	public Result save(@RequestBody JSONObject jsonObject) {
		RoomOrderGuestVO RoomOrderGuestVO = jsonObject.toJavaObject(RoomOrderGuestVO.class);
		// 参数校验
		Map<String, String> fail = FieldValidator.validateAll(RoomOrderGuestVO, "save", true);
		if (!fail.isEmpty()) {
			return validateError(fail);
		}
		Result result = new Result();
		int rows = roomOrderGuestService.save(convert(RoomOrderGuestVO));
		if (rows > 0) {
			result.setStatus(ReturnStatusEnum.SUCCESS.getCode());
			result.setMsg(ReturnStatusEnum.SUCCESS.getDesc());
			result.setReturnCode(RoomOrderGuestReturnCodeEnum.ROOM_ORDER_GUEST_SAVE_SUCCESS.getCode());
			result.setReturnMsg(RoomOrderGuestReturnCodeEnum.ROOM_ORDER_GUEST_SAVE_SUCCESS.getDesc());
		} else {
			result.setStatus(ReturnStatusEnum.FAILURE.getCode());
			result.setMsg(ReturnStatusEnum.FAILURE.getDesc());
			result.setReturnCode(RoomOrderGuestReturnCodeEnum.ROOM_ORDER_GUEST_SAVE_FAILURE.getCode());
			result.setReturnMsg(RoomOrderGuestReturnCodeEnum.ROOM_ORDER_GUEST_SAVE_FAILURE.getDesc());
		}
		return result;
	}
	@RequestMapping("update")
	@ResponseBody
	public Result update(@RequestBody JSONObject jsonObject) {
		RoomOrderGuestVO RoomOrderGuestVO = jsonObject.toJavaObject(RoomOrderGuestVO.class);
		// 参数校验
		Map<String, String> fail = FieldValidator.validateAll(RoomOrderGuestVO, "update", true);
		if (!fail.isEmpty()) {
			return validateError(fail);
		}
		Result result = new Result();
		int rows = roomOrderGuestService.updateSelective(convert(RoomOrderGuestVO));
		if (rows > 0) {
			result.setStatus(ReturnStatusEnum.SUCCESS.getCode());
			result.setMsg(ReturnStatusEnum.SUCCESS.getDesc());
			result.setReturnCode(RoomOrderGuestReturnCodeEnum.ROOM_ORDER_GUEST_UPDATE_SUCCESS.getCode());
			result.setReturnMsg(RoomOrderGuestReturnCodeEnum.ROOM_ORDER_GUEST_UPDATE_SUCCESS.getDesc());
		} else {
			result.setStatus(ReturnStatusEnum.FAILURE.getCode());
			result.setMsg(ReturnStatusEnum.FAILURE.getDesc());
			result.setReturnCode(RoomOrderGuestReturnCodeEnum.ROOM_ORDER_GUEST_UPDATE_FAILURE.getCode());
			result.setReturnMsg(RoomOrderGuestReturnCodeEnum.ROOM_ORDER_GUEST_UPDATE_FAILURE.getDesc());
		}
		return result;
	}

	@RequestMapping("delete")
	@ResponseBody
	public Result delete(@RequestBody JSONObject jsonObject) {
		RoomOrderGuestVO RoomOrderGuestVO = jsonObject.toJavaObject(RoomOrderGuestVO.class);
		// 参数校验
				Map<String, String> fail = FieldValidator.validateAll(RoomOrderGuestVO, "del", true);
				if (!fail.isEmpty()) {
					return validateError(fail);
				}
		Result result = new Result();
		int rows = roomOrderGuestService.del(RoomOrderGuestVO.getId());
		if (rows > 0) {
			result.setStatus(ReturnStatusEnum.SUCCESS.getCode());
			result.setMsg(ReturnStatusEnum.SUCCESS.getDesc());
			result.setReturnCode(RoomOrderGuestReturnCodeEnum.ROOM_ORDER_GUEST_DEL_SUCCESS.getCode());
			result.setReturnMsg(RoomOrderGuestReturnCodeEnum.ROOM_ORDER_GUEST_DEL_SUCCESS.getDesc());
		} else {
			result.setStatus(ReturnStatusEnum.FAILURE.getCode());
			result.setMsg(ReturnStatusEnum.FAILURE.getDesc());
			result.setReturnCode(RoomOrderGuestReturnCodeEnum.ROOM_ORDER_GUEST_DEL_FAILURE.getCode());
			result.setReturnMsg(RoomOrderGuestReturnCodeEnum.ROOM_ORDER_GUEST_DEL_FAILURE.getDesc());
		}
		return result;
	}

	@RequestMapping("get")
	@ResponseBody
	public Result get(@RequestBody JSONObject jsonObject) {
		RoomOrderGuestVO RoomOrderGuestVO = jsonObject.toJavaObject(RoomOrderGuestVO.class);
		Result result = new Result();
		RoomOrderGuestModel GroupModel = roomOrderGuestService.find(convert(RoomOrderGuestVO));
		if (Utils.isNotNull(GroupModel)) {
			result.setData(GroupModel);
			result.setStatus(ReturnStatusEnum.SUCCESS.getCode());
			result.setMsg(ReturnStatusEnum.SUCCESS.getDesc());
			result.setReturnCode(RoomOrderGuestReturnCodeEnum.ROOM_ORDER_GUEST_QUERY_SUCCESS.getCode());
			result.setReturnMsg(RoomOrderGuestReturnCodeEnum.ROOM_ORDER_GUEST_QUERY_SUCCESS.getDesc());
		} else {
			result.setStatus(ReturnStatusEnum.FAILURE.getCode());
			result.setMsg(ReturnStatusEnum.FAILURE.getDesc());
			result.setReturnCode(ReturnCodeEnum.NO_DATA.getCode());
			result.setReturnMsg(ReturnCodeEnum.NO_DATA.getDesc());
		}
		return result;
	}
	/**
	 * 获取同来宾客的列表信息
	 * 功能：<br/>
	 *
	 * @author sunyl
	 * @Date 2017年12月20日 上午10:27:06 <br/>
	 */
	@RequestMapping("getOrderGuestInfo")
	@ResponseBody
	public Result getOrderGuestInfo(@RequestBody JSONObject jsonObject) {
		RoomOrderGuestVO roomOrderGuestVO = jsonObject.toJavaObject(RoomOrderGuestVO.class);
		Result result = new Result();
		// 参数校验
		Map<String, String> fail = FieldValidator.validateAll(roomOrderGuestVO, "roomOrderId", true);
		if (!fail.isEmpty()) {
			return validateError(fail);
		}
		List<GuestInfoModel> finds = roomOrderGuestService.getOrderGuestInfo(roomOrderGuestVO.getRoomOrderId());
		if (Utils.isNotNull(finds) && finds.size()>0) {
			result.setData(finds);
			result.setStatus(ReturnStatusEnum.SUCCESS.getCode());
			result.setMsg(ReturnStatusEnum.SUCCESS.getDesc());
			result.setReturnCode(GuestInfoReturnCodeEnum.GUESTINFO_QUERY_SUCCESS.getCode());
			result.setReturnMsg(GuestInfoReturnCodeEnum.GUESTINFO_QUERY_SUCCESS.getDesc());
		} else {
			result.setStatus(ReturnStatusEnum.FAILURE.getCode());
			result.setMsg(ReturnStatusEnum.FAILURE.getDesc());
			result.setReturnCode(ReturnCodeEnum.NO_DATA.getCode());
			result.setReturnMsg(ReturnCodeEnum.NO_DATA.getDesc());
		}
		return result;
	}
	
}
